<template>
  <div class="login-container">
    <center><span class="title" style=" color: black; size: auto;" >国内航班后台管理系统 </span></center>
<!--    轮播图-->

    <template class="lb">
      <div class="block" ref="carousel">
        <el-carousel  height="500px"  trigger="click" :interval="3000" arrow="always">
          <el-carousel-item v-for="item in images" :key="item.name">
            <img :src="item.src"
                 :title="item.title"
                 alt="图⽚丢失了"
                 style="height:100%; width:100%;"
            />
          </el-carousel-item>
        </el-carousel>
      </div>
    </template>

    <el-form ref="loginForm" :model="loginForm"  class="login-form" auto-complete="on" label-position="left">
<!--账号-->
      <el-form-item prop="username">

        <!--        账号的图标-->
        <span class="svg-container">
          <svg-icon icon-class="user" />
        </span>

        <el-input  class="input"  v-model="loginForm.username"  type="text" auto-complete="on" placeholder="username" />

      </el-form-item>

<!--     密码 -->
      <el-form-item prop="password">
<!--        密码的图标-->
        <span class="svg-container">
          <svg-icon icon-class="password" />
        </span>

        <el-input
          class="input"
          :type="pwdType"
          v-model="loginForm.password"
          auto-complete="on"
          placeholder="password"
          @keyup.enter.native="handleLogin" />

        <span class="show-pwd" @click="showPwd">
          <svg-icon icon-class="eye" />
        </span>

      </el-form-item>

<!--      登录按钮-->
      <el-form-item>
        <el-button  type="primary" style="width:100%;" @click.native.prevent="handleLogin">
          登录
        </el-button>
      </el-form-item>

<!--        问候语-->
        <div id="app">
          <h1 v-if="grt=(ho<9?'早上好':
                    ho<12?'上午好':
                    ho<15?'中午好':
                    ho<19?'下午好':
'晚上好'
)">尊敬的管理员,{{grt}}</h1>
        </div>

    </el-form>
  </div>
</template>

<script>


export default {
  name: 'Login',
  data() {

    const validatePass = (rule, value, callback) => {
      if (value.length < 5) {
        callback(new Error('密码不能小于5位'))
      } else {
        callback()
      }
    }


    return {
      grt:'hello',
      ho:new Date().getHours(),
      images:[
        {
          src:'../../../../static/f1.jpeg'
        },
        {
          src:'../../../../static/k1.jpeg'
        },{
          src:'../../../../static/k2.jpeg'
        },{
          src:'../../../../static/f2.jpeg'
        },
      ]
      ,
      loginForm: {
        username: '',
        password: '',
      },

      pwdType: 'password',
      redirect: undefined
    }



  },
  watch: {
    $route: {
      handler: function(route) {
        this.redirect = route.query && route.query.redirect
      },
      immediate: true   //立刻执行
    }
  },

  methods: {
    //显示密码
    showPwd() {
      if (this.pwdType === 'password') {
        this.pwdType = ''
      } else {
        this.pwdType = 'password'
      }
    },
    //登录
    handleLogin() {
      this.$refs.loginForm.validate(valid => {
        if (valid) {

          this.$store.dispatch('Login', this.loginForm)
            .then(() => {
            this.loading = false
            this.$router.push({ path: this.redirect || '/' })
          })
        }
      })
    }


  }
}
</script>

<style rel="stylesheet/scss" lang="scss">
$bg:#2d3a4b;
$light_gray:#eee;

/* reset element-ui css */
.login-container {
  .el-input {
    display: inline-block;
    height: 47px;
    width: 85%;
    input {
      background: transparent;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 12px 5px 12px 15px;
      color: $light_gray;
      height: 47px;
      &:-webkit-autofill {
        -webkit-box-shadow: 0 0 0px 1000px $bg inset !important;
        -webkit-text-fill-color: #fff !important;
      }
    }
  }
  .el-form-item {
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.1);
    border-radius: 5px;
    color: #454545;
  }
}
.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 200px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n+1) {
  background-color: #d3dce6;
}
</style>


<style rel="stylesheet/scss" lang="scss" scoped>
$bg:#2d3a4b;
$dark_gray:#889aa4;
$light_gray:#eee;

//页面样式的大框
.login-container {
  position: fixed;
  height: 100%;
  width: 100%;
  background : linear-gradient(135deg,#16bffd,#cb3066);

  //账号密码的大框
  .login-form {
    //border : #6c5f96 solid 10px ;
    //border-radius: 30px;
    position: absolute;
    left: 0;
    right: 0;
    width: 530px;
    text-align: center;
    max-width: 100%;
    margin-top: 20px;
    margin-left: 600px;
  }
  //提示
  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;
    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }

  // 账号密码的图标
  .svg-container {
    padding: 6px 5px 6px 15px;
    color: #8ba3c7;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }
  //标题
  .title {
    font-size: 40px;
    //font-weight: 800;
    color: #4a4b9d;
    padding-top: 50px;
    margin: 0px auto 40px auto;
    text-align: center;
    font-weight: bolder;
  }
  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }
}
</style>
